#include "Bot.h"
#include "frand.h"

Bot::Bot()
{

	SetWalkZone(Rect(-50,-50, 50, 50));
	mAttributes.Speed(.1f);
	mAttributes.Damage(1);
	mDestination = GetRandomPoint();
	xEntityColor(mesh, 255, 128, 64);
	xEntityPickMode(mesh, PICK_TRIMESH);
}

Vec3D Bot::GetRandomPoint() const
{
	return Vec3D(frand(mWalkZone.x1, mWalkZone.x2), 0, frand(mWalkZone.y1, mWalkZone.y2));
}

void Bot::SetWalkZone(const Rect& walkZone)
{
	mWalkZone = walkZone;
}

void Bot::Update()
{
	if (InPosition(mDestination))
	{
		mDestination = GetRandomPoint();
	}
	else
	{
		if (Attaced())
		{
			DealDamage(mAttacker);
		} 
		else if(!IsDead())
		{
			MoveToPoint(mDestination);
		}
	}
	if (mAttributes.Health() == 0)
	{
		xEntityColor(mesh, 50, 0, 0);
		mAttacker = 0;
	}
}
